package com.fmboy.MXH.nav.controller;


import com.fmboy.MXH.nav.domain.ErrorCode;
import com.fmboy.MXH.nav.domain.Result.Result;
import com.fmboy.MXH.nav.domain.dto.EmailDTO;
import com.fmboy.MXH.nav.service.impl.EmailService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

@CrossOrigin
@Slf4j
@RestController
@RequestMapping("/mxh-nav")
@Tag(name = "邮件接口", description = "邮件接口")
public class EmailController {

    @Resource
    private EmailService emailService;


    @PostMapping(value = "/email")
    @Operation(summary = "发送邮件", description = "发送包含验证码的验证邮件")
    public Result<String> sendEmail(@RequestBody EmailDTO emailDTO) {
        try {
            emailService.sendVerificationEmail(emailDTO.getEmail());
            log.info("邮件发送成功: {}", emailDTO.getEmail());
            return Result.success("邮件发送成功");
        } catch (Exception e) {
            log.error("邮件发送失败: {}", e.getMessage(), e);
            return Result.error(ErrorCode.INVALID_REQUEST, "邮件发送失败");
        }
    }
}